package com.songshuai.webapi.permission.service.impl;

import com.songshuai.webapi.permission.dao.McTestMapper;
import com.songshuai.webapi.permission.model.McTest;
import com.songshuai.webapi.permission.service.McTestService;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class McTestServiceImpl implements McTestService {

    @Autowired
    private McTestMapper mcTestMapper;
    @Override
    public McTest selectMcById(Integer id) {
        McTest mcTest = mcTestMapper.selectByPrimaryKey(id);
        return mcTest;
    }

    @Override
    public List<McTest> selectMcByExample(McTest mc) {
        Example example=new Example(McTest.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andBetween("id",0,1);
        criteria.andCondition("id=",1);//id=1
        criteria.andEqualTo("id",1);//id=1
        example.isDistinct();//
        example.setOrderByClause("id desc");//按照降序
        List<McTest> mcTests = mcTestMapper.selectByExample(example);

        mcTestMapper.selectCountByExample(example);//按条件查询数量
        mcTestMapper.select(mc);//按照实体查询   自动判空
        mcTestMapper.selectByExampleAndRowBounds(example,new RowBounds(0,10));// 按条件查询 从第0条开始 查10条
        mcTestMapper.selectByRowBounds(mc,new RowBounds(0,10));


        return mcTests;
    }

    @Override
    public Integer insertMcByExample(McTest mc) {
        mcTestMapper.insert(mc);//全列插入
        int i = mcTestMapper.insertSelective(mc);//会自动判空  只插有值的d

        return i;
    }

    @Override
    public Integer updateMcByExample(McTest mc) {
        mcTestMapper.updateByPrimaryKey(mc);//按照主键全列更新
        mcTestMapper.updateByPrimaryKeySelective(mc);//按照主键  自行判空，有值的进行更新
        Example example=new Example(McTest.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("name","zhangsan");
        mcTestMapper.updateByExample(mc,example);//按照条件全列更新
        mcTestMapper.updateByExampleSelective(mc,example);//按照主键和条件  自行判空，有值的进行更新
        return null;
    }
}
